package cn.supermarket.controller;


import cn.supermarket.pojo.dto.AddVipDTO;
import cn.supermarket.pojo.dto.VipInfoDTO;
import cn.supermarket.pojo.vo.VipSimpleVO;
import cn.supermarket.service.iservice.IVIPService;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;



@RestController
@RequestMapping("/vip")
@Api(tags = "会员模块")
public class VipController extends BaseController{

    @Autowired
    private IVIPService vipService;

    @PostMapping("/reg")
    @ApiOperation("会员注册")
    public JsonResult regVip(AddVipDTO addVipDTO){
       vipService.regVip(addVipDTO);
        return JsonResult.ok("注册完成!");
    }


  @GetMapping("/add/amount")
  @ApiOperation("会员储值卡充值")
  public JsonResult addAmount(String phone, BigDecimal amount){
      vipService.addAmount(phone,amount);
      return JsonResult.ok("充值完成!");
  }

    @GetMapping("/sub/amount")
    @ApiOperation("会员储值卡消费")
    public JsonResult subAmount(String phone, BigDecimal amount){
        vipService.subAmount(phone,amount);
        return JsonResult.ok("消费完成!");
    }

    @PostMapping("/update-info")
    @ApiOperation("修改会员基本信息")
    public JsonResult updateVipInfo(VipInfoDTO vipInfoDTO){
        vipService.updateVipInfo(vipInfoDTO);
        return JsonResult.ok("修改完成!");
    }

    @GetMapping("/cancel/{phone}")
    @ApiOperation("会员注销")
    public JsonResult vipCancel(@PathVariable String phone){
        vipService.updateCancel(phone);
        return JsonResult.ok("注销完成!");
    }


    @GetMapping("/show-all")
    @ApiOperation("会员列表")
    public JsonResult<List<VipSimpleVO>> vipList(){
        List<VipSimpleVO> vipList = vipService.getVipList();
        return JsonResult.ok(vipList);
    }




}
